﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Content;
using Imaginecup.shareData;
using Microsoft.Xna.Framework.Graphics;
using Imaginecup.util.resourceMan;
using Microsoft.Xna.Framework;
using Imaginecup.sprite;
using Imaginecup.sprite.animation;
using imaginecup.util;
using Imaginecup.gameState.intro;

namespace Imaginecup.gameState.ending.unuse
{
    public class EndingScene1
    {
        private ISprite m_Sprite;
        private EntityInfo m_Info;

        private int m_InitY;
        private AnimationIndexMan m_IndexMan;

        private bool m_bEnd;

        public EndingScene1()
        {
            m_InitY = 0;
            m_bEnd = false;
            m_Info = new EntityInfo(0, 0, 800, 480);
        }

        public void LoadEndingScene()
        {
            m_IndexMan = new AnimationIndexMan();
            m_IndexMan.SetDelay(0.125);
            m_IndexMan.SetIndex(new Vector2(0, 0), 18);
            m_IndexMan.StartAnimation();

            AnimationSpriteByTexture textureSprite = new AnimationSpriteByTexture(m_IndexMan);

            for (int i = 1; i <=  18; i++ )
            {
                textureSprite.AddTextureName( "ending\\1\\" + i);
            }

            m_Sprite = textureSprite;

        }

        public void UnloadEndingScene()
        {
          // m_Content.Unload();
            m_Sprite.Release();
            m_IndexMan = null;
        }
        
        public void Update(GameTime gameTime , ScrollMan scrollMan)
        {
            if (m_bEnd) return;

            m_Info.mPosition.Y = m_InitY - scrollMan.GetCurrentStartPos().Y;

            if( m_Info.mPosition.Y < -480 ) // 화면 사이즈 보다 작다면?
            {
                UnloadEndingScene();
                m_bEnd = true;
                return;
            }

            m_IndexMan.Update(gameTime);

            if( m_IndexMan.IsLastIndex() )
            {
                m_IndexMan.StopAnimation();
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            if (m_bEnd) return;
            m_Sprite.Draw(spriteBatch , m_Info);
        }
    }
}
